﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace xna_game_engine.source
{
    abstract public class BaseWizard
    {
        public enum FaceButtons { A_BUTTON, B_BUTTON, X_BUTTON, Y_BUTTON, R_TRIGGER, L_TRIGGER, R_BUMPER, L_BUMPER };

        //protected int mNormalAttackMin, mNormalAttackMax;
        protected TongaTimer mNormalAtkTimer;
        protected List<BaseSpell> mSpells;
        protected Dictionary<FaceButtons, BaseSpell> mSpellMap;
        protected float mCurHp, mMaxHp;
        protected Vector2 mPos;
        protected int mSpeed;
        protected String mName;
        protected Texture2D mFrameImage, mModel;
        protected Rectangle mBoundingBox;
        protected PlayerIndex playerIndex;
        protected bool mIsReflective;

        public BaseWizard()
        {
            // Setup our members
            mNormalAtkTimer = new TongaTimer(0.6);
            mCurHp = mMaxHp = 100;
            SetupSkills();
            mPos = new Vector2(400.0f, 200.0f);
            mIsReflective = false;
        }

        abstract public void Update(GameTime gt);

        virtual public void Draw()
        {
            GameSystems.Graphics.DrawImage(mModel, mPos, Color.Red);
        }

        public void OnSpellUse(FaceButtons button)
        {
            if (mSpellMap.ContainsKey(button))
            {
                GameGlobals.SpellManager.AddSpell(mPos, mSpellMap[button].Clone());
            }
        }

        /// <summary>
        /// Modify the character's health value
        /// </summary>
        /// <param name="amount">Amount to modify health, send negative to hurt</param>
        virtual public void ModHealth(float amount, Color textColor)
        {
            mCurHp += amount;
            mCurHp = MathHelper.Clamp(mCurHp, 0.0f, mMaxHp);
        }

        private void SetupSkills()
        {
            mSpells = new List<BaseSpell>();
            mSpellMap = new Dictionary<FaceButtons, BaseSpell>();
            //mSkills.Add(new SkillWarDevastate(this));
            //mSkills.Add(new SkillWarBrutalize(this));
            //mSkillMap[FaceButtons.A_BUTTON] = mSkills[0];
            //mSkillMap[FaceButtons.B_BUTTON] = mSkills[1];
            //mDevastateSkill = new SkillWarDevastate(this);
            //mBrutalizeSkill = new SkillWarBrutalize(this);
        }

        public void MapSpell(BaseSpell spell, FaceButtons button)
        {
            mSpellMap[button] = spell;
        }

        // properties
        #region Properties
        public float CurHealth
        {
            get { return mCurHp; }
            set { mCurHp = value; }
        }

        public float MaxHealth
        {
            get { return mMaxHp; }
            set { mMaxHp = value; }
        }

        public string Name
        {
            get { return mName; }
        }

        public Vector2 Position
        {
            get { return mPos; }
        }

        public Texture2D UnitFrameImage
        {
            get { return mFrameImage; }
        }

        public float HealthPercent
        {
            get { return mCurHp / mMaxHp; }
            //set { mCurHp = mMaxHp * value; }
        }

        public Rectangle Bounds
        {
            get { return mBoundingBox; }
        }

        public bool Reflective
        {
            get { return mIsReflective; }
            set { mIsReflective = value; }
        }
#endregion
    }
}
